/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
//import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 *
 * @author josegarcia
 */
public class MainClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        Socket Socket = null;
        ObjectOutputStream out = null;
        BufferedReader in = null;
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        while(true){
        try {
            Socket = new Socket("localhost", 2221);
            out = new ObjectOutputStream(Socket.getOutputStream());
            in = new BufferedReader(new InputStreamReader(Socket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Cannot find host");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for host.");
            System.exit(1);
        }

        
        String serverInput;
        String userInput=null;

	while(userInput==null){
	    userInput = stdIn.readLine();
		if (userInput != null&& !userInput.equals("QUIT")) {
		    out.writeObject(userInput);
	        }
	}
        serverInput = in.readLine();
        
            System.out.println("Server Response: " + serverInput);
            



	    



        

        out.close();
        in.close();
        
        Socket.close();}
    }

}
